<?php

class SmartItems extends CWidget{
	public $dirName = 'push';
	public $fileName = '';
	public $breakId = 3;
	public $extClass = '';
	public $express = 0;
	public $apiCfg = array();

	public function run(){
		$defaultCfg= array(
			'method' => 'taobao.taobaoke.items.get',
			'fields' => 'num_iid,title,pic_url,volume,price,shop_click_url,seller_credit_score,click_url',
			'page_size' => 15,
//			'sort' => 'commissionNum_desc',
			'sort' => 'commissionNum_desc',
			'start_credit' => '1crown',
			'sevendays_return' => '1',
			'real_describe' => '1',
			'cid' => 0,
			'keyword' => '',
			'outer_code'=>'miyifun',
		);

		$config = array_merge($defaultCfg,$this->apiCfg);
		//print_r($config);
		$api = new TaobaoApi($config);
		$result = $api->getData($this->express, $this->dirName, $this->fileName);
		
		if(!count($result['taobaoke_items_get_response']['taobaoke_items']['taobaoke_item'])){
			echo '没有符合条件的商品，请重新查询';
		}else{

			foreach($result['taobaoke_items_get_response']['taobaoke_items']['taobaoke_item'] as $k => $item){
				if($k>$this->breakId) break;
				$push_title = strip_tags($item['title']);
				echo '<div class="good_wp">
						<div class="good_info '.$this->extClass.'">
							<div class="good_img push_img">
								<a target="_blank" href="'.Yii::app()->createUrl('direct/index',array('id'=>$item['num_iid'])).'"><img alt="'.$push_title.'" src="'.$item['pic_url'].'" /></a>
							</div>
							<p class="good_title"><a title="'.$push_title.'" target="_blank" href="'.Yii::app()->createUrl('direct/index',array('id'=>$item['num_iid'])).'">'.mb_substr($push_title,0,34,'utf-8').'</a></p>
							<p class="good_price"><span>￥</span>'.$item['price'].'<span class="volume"> (30天售出 '.$item['volume'].' 件)</span></p>
							<p class="good_credit"><a class="seven_return" onfocus="this.blur();" href="javascript:void(0);" title="七天退换">七天退换</a><a class="real_desc" onfocus="this.blur();" href="javascript:void(0);" title="如实描述">如实描述</a><img src="'.Yii::app()->baseUrl.'/images/credit/'.$item['seller_credit_score'].'.gif" /></p>
						</div>
					</div>
					';
			}
			echo '<div class="clear"></div>';
		}
	}

}
?>
